const request = function(url, methodP, dataContent, token = "") {
	// 默认为开启错误提示
	return new Promise((resolve, reject) => {
		uni.request({
			url: url, //由基础路径和接口地址
			method: methodP, //请求的方式必须大写
			data: dataContent, //参数
			header: {
				'Content-Type': 'application/json',
				'satoken': token
			},
			success: (res) => {

				if (res.data.code == 0) {
					resolve(res.data)
				} else if (res.data.code == 10001) {
					var showLogin = getApp().globalData.showLogin;

					if (showLogin) {

					} else {
						
						getApp().globalData.showLogin = true;
						uni.showModal({
							title: "你没有登录",
							confirmText: "登录",
							showCancel: false,
							success: function() {
							
								if (url.includes("gotoPayPage")) {
									uni.navigateTo({
										url: "/pages/Login/Login?openUrl="+"/pages/Coin/Coin?openType=1"
									})
								} else {
									uni.navigateTo({
										url: "/pages/Login/Login"
									})
								}

							}
						})
					}

					reject(res.data)
				} else {
					uni.showToast({
						title: res.data.message
					})
					reject(res.data)
				}
			},
			//失败调用reject，
			fail: (err) => {
				var temp = {};
				temp.code = 777777;
				temp.message = "网络请求错误";
				temp.data = err;
				console.log(err)
				reject(temp)
			}
		});
	})
}

export default request;